package com.cachopoid.utils;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.cachopoid.R;
import com.cachopoid.vo.CachopoVO;

public class ListaCachoposBaseAdapter extends BaseAdapter {
	 
	private static ArrayList<CachopoVO> cachopoArrayList;
	private LayoutInflater l_Inflater;
	
	 
	public ListaCachoposBaseAdapter(Context context, ArrayList<CachopoVO> results) {
		cachopoArrayList = results;
	  l_Inflater = LayoutInflater.from(context);
	}
	 
	public int getCount() {
	  return cachopoArrayList.size();
	}
	 
	public Object getItem(int position) {
	  return cachopoArrayList.get(position);
	}
	 
	public long getItemId(int position) {
	  return position;
	}
	 
	public View getView(int position, View convertView, ViewGroup parent) {
		  ViewHolder holder;
		  if (convertView == null) {
		   convertView = l_Inflater.inflate(R.layout.template_listacachopos_detalle, null);
		   holder = new ViewHolder();
		   holder.txtCachopoNombre = (TextView) convertView.findViewById(R.id.nombreCachopo);
		//   holder.txtCachopoDescripcion = (TextView) convertView.findViewById(R.id.descripcion);
		   holder.rtPuntuacionMediaBar = (RatingBar) convertView.findViewById(R.id.puntuacionMediaBar);
		   holder.txtPuntuacionMedia = (TextView) convertView.findViewById(R.id.txtPuntuacionMedia);
		 
		   convertView.setTag(holder);
		  } else {
		   holder = (ViewHolder) convertView.getTag();
		  }
		  
		  holder.txtCachopoNombre.setText(cachopoArrayList.get(position).getNombre());
		//  holder.txtCachopoDescripcion.setText(cachopoArrayList.get(position).getDescripcion());
		  holder.txtPuntuacionMedia.setText(cachopoArrayList.get(position).getMediaDeVotos().toString());
		  holder.rtPuntuacionMediaBar.setRating(cachopoArrayList.get(position).getMediaDeVotos().floatValue());
		
	  return convertView;
	}
	 
	static class ViewHolder {
		 TextView txtCachopoNombre;
	//	 TextView txtCachopoDescripcion;
		 RatingBar rtPuntuacionMediaBar;
		 TextView txtPuntuacionMedia;
	}
	 
	
}
